<template>
  <div class="index">
    <el-container>
      <el-header>
        <el-row>
          <el-col :span="3" class="logo"><p style="color: #8B4513">JT-LOGO</p></el-col>
          <el-col :span="16"><h2 style="color: #8B4513">SpringRBAC</h2></el-col>
          <el-col :span="4" class="logout">
            <el-dropdown >
              <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
              <el-icon class="el-icon--right">
                <arrow-down />
              </el-icon>

              <template #dropdown>
                <el-dropdown-item @click="router.push('/profile')">个人资料</el-dropdown-item>
                <el-dropdown-item @click="handleLogout">登出</el-dropdown-item>
              </template>
            </el-dropdown>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <el-aside width="240px">
          <el-menu :default-active="'1'" router
                   :unique-opened="true"
                   background-color="#F2F3F5">
            <el-menu-item index="1" route="/dashboard">
              <el-icon><HomeFilled /></el-icon>首页
            </el-menu-item>
            <!-- Top-level menu items -->
            <el-sub-menu v-for="item in menuTree" :key="item.menuId" :index="item.url">
              <template #title>
                <el-icon>
                  <component :is="item.icon"/>
                </el-icon>
                {{ item.nameZh }}
              </template>
              <!-- Sub-menu items -->
              <el-menu-item v-for="child in item.children" :key="child.menuId" :route="child.url" :index="child.nameZh">
                <el-icon>
                  <component :is="child.icon"/>
                </el-icon>
                {{ child.nameZh }}
              </el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-aside>
        <el-main style="background-color: #F2F3F5; padding: 0">
          <el-space direction="vertical" style="margin-top: 10px">
            <Tags/>
          </el-space>
          <el-card>
            <router-view/>
          </el-card>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">

import {MainStore} from "../store/MainStore.ts";
import {ArrowDown, HomeFilled} from "@element-plus/icons-vue";
import router from "../router/router.ts";
import Tags from "@/components/Tags.vue";


const mainStore = MainStore()

const menuTree = mainStore.getMenuTree()


function handleLogout(){

  sessionStorage.setItem('isLogin', 'false')
  sessionStorage.removeItem('menu')

  router.push({ path: '/login', replace: true})
}

</script>

<style lang="scss" scoped>
.index{
  background-color: #F2F3F5;
}

.el-header{

  height: 50px;
  padding: 0;
  background-color: #FDEB71;

  .logo{
    display: block;
    text-align: center;
    font-weight: 700;
    font-size: 20px;
    line-height: 50px;


    border-right: solid 1px #DCDFE6;
  }

  .navbar{
    background: #0d0c1e;
    width: 100%;
    height: 100%;
    text-align: center;
  }

  h2, .logout{
    text-align: center;
    height: 50px;
    line-height: 50px;
  }

  .logout{
    margin-top: 5px;
  }
}

.el-aside{


  .el-menu{
    height: calc(100vh - 50px);
  }
}
</style>